import Vue from 'vue'
import Vuex from 'vuex'
import goods from './goods'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 登录框得状态
    isOpenLogin:false,
    // 提示对象
    toast:{
      // 提示框显示状态
    isShowToast:false,
    // 提示内容
    content:'4123412414',
    // 图标
    icon:'icon-toast-jinggao'
    }
    
  },
  getters: {
  },
  mutations: {
    // 登录框修改状态的方法
    changeIsLogin(state,paylod){
      state.isOpenLogin = paylod
    },
    // 提示组件
    changeIsToast(state,paylod){
      state.toast.isShowToast = true
      state.toast.content =paylod.content
      switch(paylod.icon){
        case"info":
        state.toast.icon = "icon-toast-jinggao";
        break;
        case"success":
        state.toast.icon = "icon-toast_chenggong";
        break;
        case "danger":
          state.toast.icon = "icon-toast-shibai_huaban";
          break;
        case "loading":
          state.toast.icon = "icon-loading";
          break;
        default:
          state.toast.icon = "icon-toast-jinggao";
          break;
      }
    },
    // 同步关闭组件
    closeToast(state){
      state.toast.isShowToast = false
    }
  },
  actions: {
    AsncToast({
      commit
    },paylod){
      commit('changeIsToast',paylod);
      setTimeout(() =>{
        commit('closeToast')
      },3000)
    }
  },
  modules: {
    goods
  }
})
